﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Znice
{
    public class TextFormatFactory
    {
        /// <summary>
        /// 根据枚举key名称，获取枚举 Value
        /// </summary>
        /// <param name="name">key名称</param>
        /// <returns></returns>
        public static ToolBar GetEnumValue(string name)
        {
            return (ToolBar)Enum.Parse(typeof(ToolBar), name);
        }

        /// <summary>
        /// 创建点击按钮格式
        /// </summary>
        /// <param name="toolBarName">枚举key名称</param>
        /// <returns></returns>
        public static ITextFormat CreateTextFormat(string? toolBarName)
        {
            if (toolBarName == null)
            {
                return new DefaultFormat();
            }
            else
            {
                var toolBar = GetEnumValue(toolBarName);
                return toolBar switch
                {
                    ToolBar.Bold => new BoldFormat(),
                    ToolBar.Italic => new ItalicFormat(),
                    ToolBar.Font => new FontFormat(),
                    ToolBar.PlusFontSize => new PlusFontSizeFormat(),
                    ToolBar.MinusFontSize => new MinusFontSizeFormat(),
                    ToolBar.AlignLeft => new LeftFormat(),
                    ToolBar.AlignCenter => new CenterFormat(),
                    ToolBar.AlignRight => new RightFormat(),
                    ToolBar.UnorderedList => new UnorderedListFormat(),
                    ToolBar.StrikeThrough => new StrikeThroughFormat(),
                    ToolBar.UnderLine => new UnderLineFormat(),
                    ToolBar.SubScript => new SubScriptFormat(),
                    ToolBar.SuperScript => new SuperScriptFormat(),
                    ToolBar.Table => new TableFormat(),
                    ToolBar.BackgroundColor => new BackgroundColorFormat(),
                    ToolBar.ForeColor => new ForeColorFormat(),
                    ToolBar.Indent => new IndentFormat(),
                    ToolBar.Outdent => new OutdentFormat(),
                    ToolBar.Undo => new UndoFormat(),
                    ToolBar.Redo => new RedoFormat(),
                    ToolBar.Delete => new DeleteFormat(),
                    ToolBar.Link => new LinkFormat(),
                    //ToolBar.UnLink => new DefaultFormat(),
                    ToolBar.Picture => new PictureFormat(),
                    ToolBar.Print => new PrintFormat(),
                    ToolBar.Open => new OpenFormat(),
                    ToolBar.SaveAs => new SaveAsFormat(),
                    _ => new DefaultFormat(),
                };
            }
        }
    }
}
